//
//  StoreDetailPackageListCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "StoreDetailPackageCollectionCell.h"

#import "StoreDetailPackageListCell.h"

@interface StoreDetailPackageListCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>{
    CGSize _cellSize;
    UIEdgeInsets _collectionEdge;
}

@end

@implementation StoreDetailPackageListCell

+ (CGFloat)calculateHeightWithItemCount:(NSInteger)count {

    CGFloat collectionWidth = TTScreenWidth - 20;
    CGFloat distance = 5;
    CGFloat simpleHeight = 1.2 * (collectionWidth/2 - 2*distance);
    simpleHeight = simpleHeight + 4*distance;
    
    if (count<=2) {
    } else {
        simpleHeight = simpleHeight*2;
    }
    return simpleHeight;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];

    CGFloat width = TTScreenWidth - 20;
    
    CGFloat cellWidth;
    CGFloat distance = 5;
    cellWidth = width/2 - 2*distance;

    _cellSize =  CGSizeMake(cellWidth, 1.2 * cellWidth);
    _collectionEdge = UIEdgeInsetsMake(distance, distance, distance, distance);
    
    
    UICollectionViewFlowLayout *flowLaout = [[UICollectionViewFlowLayout alloc]init];
    flowLaout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.collectionview.collectionViewLayout = flowLaout;
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    self.collectionview.showsHorizontalScrollIndicator = NO;
    self.collectionview.showsVerticalScrollIndicator = NO;
    
    [self.collectionview registerNib:[UINib nibWithNibName:@"StoreDetailPackageCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"StoreDetailPackageCollectionCellID"];

}

- (void)fillCellWithModel {
    
    [self.collectionview reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    StoreDetailPackageCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StoreDetailPackageCollectionCellID" forIndexPath:indexPath];
//    [cell fillCellWithModel:self.dataArray[indexPath.row]];

    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return _cellSize;
}

//设置cell的位置
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                       layout:(UICollectionViewLayout *)collectionViewLayout
       insetForSectionAtIndex:(NSInteger)section {

    return _collectionEdge;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

}




@end
